package com.lg.spring.controller;

import com.lg.spring.kafka.KafkaMessage;
import com.lg.spring.kafka.producer.KafkaProducer;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author by Mr. Li 2020/9/15 13:03
 */
@RestController
@RequestMapping(value = "/kafka", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class KafkaController {

	//@Resource
	private KafkaProducer kafkaProducer;

	@GetMapping("message")
	public KafkaMessage sendKafkaMessage(@RequestParam("id") long id,
										 @RequestParam("username") String username,
										 @RequestParam("password") String password) {
		System.out.println("sendKafkaMessage invoked!");

		KafkaMessage kafkaMessage = new KafkaMessage();

		kafkaMessage.setId(id);
		kafkaMessage.setUsername(username);
		kafkaMessage.setPassword(password);

		this.kafkaProducer.sendKafkaMessage(kafkaMessage);

		return kafkaMessage;

	}
}
